package org.linlinjava.litemall.db.vo.order_manage;

import com.alibaba.fastjson.JSON;
import org.apache.commons.lang.StringUtils;
import org.linlinjava.litemall.db.jsonfield.LitemallGoodsProductSpecification;

import java.util.List;

/**
 * 管理订单单条新记录
 * @author houzb
 * @Description
 * @create 2021-08-31 20:46
 */
public class AgedAdminOrderItemInfoVo {

    /**
     * 主订单id
     * litemall_order的id
     */
    private int mainId;
    /**
     * 商品订单的id
     * litemall_order_goods的id
     */
    private int subId;
    /**
     * 商品的图片
     */
    private String picUrl;
    /**
     * 商品的名称
     */
    private String goodsName;
    /**
     * 商品的规则信息，json串
     */
    private String specifications;
    /**
     * 下单时间
     */
    private String createTime;
    /**
     * 订单的字符串编号
     */
    private String orderSn;

    /**
     * 订单状态
     */
    private String orderStatus;

    /**
     * 店铺名称
     */
    private String storeName;
    /**
     * 配送费
     */
    private double freightPrice;
    /**
     * 取货费用
     * TODO 还未获取
     */
    private double pickPrice;
    /**
     * 维护费用
     * //TODO 还未获取
     */
    private double maintainPrice;


    /**
     * 送货费
     */
    private double deliveryPrice;

    /**
     * 发送的状态
     * 1 待配货，2 待送货
     */
    private int sendStat;
    /**
     * 取货时间
     * null 待取货，非空 待维护
     */
    private String pickTime;
    /**
     * 0待结算 1 已结算
     */
    private int isSettle;
    /**
     * 购买的数量
     */
    private int counts;

    /**
     * 配送员
     */
    private String arkiName;

    /**
     * 运送员
     */
    private String deliveryName;

    /**
     * 维护人员
     */
    private String maintainName;

    /**
     * 取货人员
     */
    private String pickName;






    public String getPickName() {
        return pickName;
    }

    public void setPickName(String pickName) {
        this.pickName = pickName;
    }

    public String getArkiName() {
        return arkiName;
    }

    public void setArkiName(String arkiName) {
        this.arkiName = arkiName;
    }

    public String getDeliveryName() {
        return deliveryName;
    }

    public void setDeliveryName(String deliveryName) {
        this.deliveryName = deliveryName;
    }

    public String getMaintainName() {
        return maintainName;
    }

    public void setMaintainName(String maintainName) {
        this.maintainName = maintainName;
    }

    public double getDeliveryPrice() {
        return deliveryPrice;
    }

    public void setDeliveryPrice(double deliveryPrice) {
        this.deliveryPrice = deliveryPrice;
    }

    public String getOrderStatus() {
        return orderStatus;
    }

    public void setOrderStatus(String orderStatus) {
        this.orderStatus = orderStatus;
    }

    public int getMainId() {
        return mainId;
    }

    public void setMainId(int mainId) {
        this.mainId = mainId;
    }

    public int getSubId() {
        return subId;
    }

    public void setSubId(int subId) {
        this.subId = subId;
    }

    public String getPicUrl() {
        return picUrl;
    }

    public void setPicUrl(String picUrl) {
        this.picUrl = picUrl;
    }

    public String getGoodsName() {
        return goodsName;
    }

    public void setGoodsName(String goodsName) {
        this.goodsName = goodsName;
    }

    public String getSpecifications() {
        return specifications;
    }

    public void setSpecifications(String specifications) {
        this.specifications = specifications;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getOrderSn() {
        return orderSn;
    }

    public void setOrderSn(String orderSn) {
        this.orderSn = orderSn;
    }

    public String getStoreName() {
        return storeName;
    }

    public void setStoreName(String storeName) {
        this.storeName = storeName;
    }

    public double getFreightPrice() {
        return freightPrice;
    }

    public void setFreightPrice(double freightPrice) {
        this.freightPrice = freightPrice;
    }

    public double getPickPrice() {
        return pickPrice;
    }

    public void setPickPrice(double pickPrice) {
        this.pickPrice = pickPrice;
    }

    public double getMaintainPrice() {
        return maintainPrice;
    }

    public void setMaintainPrice(double maintainPrice) {
        this.maintainPrice = maintainPrice;
    }

    public int getSendStat() {
        return sendStat;
    }

    public void setSendStat(int sendStat) {
        this.sendStat = sendStat;
    }

    public String getPickTime() {
        return pickTime;
    }

    public void setPickTime(String pickTime) {
        this.pickTime = pickTime;
    }

    public int getIsSettle() {
        return isSettle;
    }

    public void setIsSettle(int isSettle) {
        this.isSettle = isSettle;
    }

    public int getCounts() {
        return counts;
    }

    public void setCounts(int counts) {
        this.counts = counts;
    }

    public String getStatShow() {
        if(this.sendStat == 1) {
            return "待配货";
        }else if(this.sendStat == 2) {
            return "待送货";
        }else if(StringUtils.isBlank(this.pickTime)) {
            return "待取货";
        }else if(StringUtils.isNotBlank(this.pickTime)){
            return "待维护";
        }else if(this.isSettle == 0) {
            return "待结算";
        }else if(this.isSettle == 1) {
            return "已结算";
        }
        return "--";
    }

    public AgedAdminOrderGoodsVo  getOrderGoodsVo(AgedAdminOrderItemInfoVo itemInfo){
        AgedAdminOrderGoodsVo goodsVo = new AgedAdminOrderGoodsVo();
        goodsVo.setOrderStat(getStatShow());
        //TODO
        goodsVo.setDeliverPrice(itemInfo.getFreightPrice(), itemInfo.getArkiName() == null ? "无" : itemInfo.getArkiName());
        //TODO
        goodsVo.setDistributionPrice(itemInfo.getDeliveryPrice(), itemInfo.getDeliveryName() == null ? "无" : itemInfo.getDeliveryName());
        //TODO
        goodsVo.setPickPrice(itemInfo.getPickPrice(), itemInfo.getPickName() == null ? "无" : itemInfo.getPickName());
        //TODO
        goodsVo.setMaintainPrice(itemInfo.getMaintainPrice(), itemInfo.getMaintainName() == null ? "无" : itemInfo.getMaintainName());
        OrderDetailGoodsVo detailGoodsVo = new OrderDetailGoodsVo();
        detailGoodsVo.setGoodsPic(itemInfo.getPicUrl());
        List<LitemallGoodsProductSpecification> specifications
                = JSON.parseArray(itemInfo.getSpecifications(), LitemallGoodsProductSpecification.class);
        StringBuffer specificationInfo = new StringBuffer();
        for(LitemallGoodsProductSpecification lgs : specifications){
            specificationInfo.append(lgs.getInfoName()).append(",").append(lgs.getName()).append(":");
        }
        String specInfo = specificationInfo.substring(0,specificationInfo.length() - 1 );
        detailGoodsVo.setGoodsSpec(specInfo);
        detailGoodsVo.setGoodsName(itemInfo.getGoodsName());
        detailGoodsVo.setNumber(itemInfo.getCounts());
        goodsVo.setGoodsDetail(detailGoodsVo);

        return goodsVo;
    }

}
